const rl = @import("raylib");
const shape = @import("../shape.zig");
const setting = @import("../setting.zig");

const IndexBlock = @import("index_block.zig");
const Map = @import("../map.zig");

const Food = @This();

const MinEneryg: u32 = 15;
const MaxEnergy: u32 = 35;

var cur_id: u32 = 0;

map: *Map,
index_block: *IndexBlock,

id: u32,
x: f32,
y: f32,
energy: f32,
energy_efficiency: f32 = 1.0, // 每秒能提供的能量

pub fn init(map: *Map) *@This() {
    const item = map.allocator.create(Food) catch @panic("Out of memory");

    item.id = cur_id;
    item.map = map;
    item.energy = @floatFromInt(map.rand.intRangeAtMost(u32, MinEneryg, MaxEnergy));
    item.x = map.randX();
    item.y = map.randY();

    map.index.index(@This(), item, true);

    cur_id += 1;

    return item;
}

pub fn deinit(self: *@This()) void {
    self.map.allocator.destroy(self);
}

pub fn prepare(self: *@This()) void {
    _ = self;
}

pub fn do(self: *@This()) void {
    _ = self;
}

pub fn post(self: *@This()) void {
    _ = self;
}

pub fn draw(self: *@This()) void {
    shape.drawTriangle(self.x, self.y, setting.food_height, &rl.Color.green);
}
